package com.talkweb.securitycamera.data.hadoopFile;

import com.talkweb.dataprocesslib.ResourceTable;
import com.talkweb.securitycamera.common.base.utils.ResourceHelper;
import com.talkweb.securitycamera.common.constans.FileType;
import com.talkweb.securitycamera.common.interfaces.dataprocess.FileCallback;
import com.talkweb.securitycamera.utils.TimeUtils;
import ohos.app.Context;
import ohos.app.dispatcher.task.TaskPriority;

import java.io.*;

/**
 * 查询视频文件与插入视频文件的类
 * class to query video files and save video files
 *
 * @author : frank
 * @date : 2021/2/2 10:03
 */
public class SimpleVideoProcessor extends BaseMediaProcessor<InputStream> {

    private Context mContext;

    private SimpleVideoMemoryPolicy videoMemoryPolicy;

    /**
     * construct instance to query and write
     * @param context
     * @param fileCallback
     */
    public SimpleVideoProcessor(Context context, FileCallback fileCallback) {
        mContext = context.getApplicationContext();
        videoMemoryPolicy = new SimpleVideoMemoryPolicy();
    }

    /**
     * construct instance to query
     * @param context
     */
    public SimpleVideoProcessor(Context context) {
        mContext = context.getApplicationContext();
    }


    @Override
    public Context getContext() {
        return mContext;
    }

    @Override
    public void addFile(InputStream source, FileType type) {
        super.addFile(source, type);

    }

    @Override
    public File createSourceFile(FileType fileType) {
        checkMemory(videoMemoryPolicy, mContext);
        String suffix = ResourceHelper.getString(mContext, ResourceTable.String_video_suffix);
        File mediaDirectory = MediaDirectoryProvider.provideMediaDirectory(mContext, fileType);
        String hadoopFilePath = mediaDirectory.getAbsolutePath() + File.separator + TimeUtils.getTimeYYYYMMddHHmmss(System.currentTimeMillis()) + suffix;
        return new File(hadoopFilePath);
    }
}
